#include<stdio.h>
#include<unistd.h>
#include <sys/types.h>

int gval = 100;

int main()
{
    int pid = fork();
    if(pid==0)
    {
        while(1)
        {
            sleep(1);
            printf("子进程pid:%d,父进程pid:%d\n",getpid(),getppid());
            printf("gval:%d->%d\n",gval,gval+10);
            gval+=10;
        }
    }
    else if(pid>0)
    {
        while(1)
        {
            sleep(5);
            printf("父进程pid:%d\n",getpid());
            printf("gval:%d\n",gval);
        }
    }
    else
    {
        perror("fork\n");
        return 1;
    }
    return 0;
}
